package com.ruoyi.information.controller.pc;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.information.domain.pc.FeedBack;
import com.ruoyi.information.service.pc.IFeedBackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 投诉建议Controller
 *
 * @author ruoyi
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/back")
public class FeedBackController extends BaseController
{
    @Autowired
    private IFeedBackService feedBackService;

    /**
     * 查询投诉建议列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FeedBack feedBack)
    {
        startPage();
        List<FeedBack> list = feedBackService.selectFeedBackList(feedBack);
        return getDataTable(list);
    }

    /**
     * 导出投诉建议列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeedBack feedBack)
    {
        List<FeedBack> list = feedBackService.selectFeedBackList(feedBack);
        ExcelUtil<FeedBack> util = new ExcelUtil<FeedBack>(FeedBack.class);
        util.exportExcel(response, list, "投诉建议数据");
    }

    /**
     * 获取投诉建议详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(feedBackService.selectFeedBackById(id));
    }

    /**
     * 新增投诉建议
     */
    @PostMapping
    public AjaxResult add(@RequestBody FeedBack feedBack)
    {
        feedBack.setUserId(SecurityUtils.getUserId());
        return toAjax(feedBackService.insertFeedBack(feedBack));
    }

    /**
     * 修改投诉建议
     */
    @PutMapping
    public AjaxResult edit(@RequestBody FeedBack feedBack)
    {
        return toAjax(feedBackService.updateFeedBack(feedBack));
    }

    /**
     * 删除投诉建议
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(feedBackService.deleteFeedBackByIds(ids));
    }
}
